import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/Users.vue'
import Rights from '../components/power/Rights.vue'
import Roles from '../components/power/Roles.vue'
import Cate from '../components/goods/Cate.vue'
import Params from '../components/goods/Params'
import GoodsList from '../components/goods/List.vue'
import Add from '../components/goods/Add'
import Orders from '../components/orders/Orders'
import Tabs from '../components/component/tabs'
import aa from '../components/component/aa'
import bb from '../components/component/bb'
import cc from '../components/component/cc'
import Report from '../components/component/reports'
import error404 from '../components/utils/error404'
// import Tabsdemo from '../components/component/tabsdemo'
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  { path: '/404', component: error404, hidden: true },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      {
        path: '/welcome', component: Welcome
      },
      {
        path: '/users', component: Users
      },
      { path: '/rights', component: Rights },
      { path: '/roles', component: Roles },
      { path: '/categories', component: Cate },
      { path: '/params', component: Params },
      { path: '/goods', component: GoodsList },
      { path: '/add', component: Add },
      { path: '/orders', component: Orders },
      { path: '/reports', component: Report },
      {
        path: '/tabs',
        component: Tabs,
        children: [
          { path: '/aa', name: 'aa', component: aa },
          { path: '/bb', name: 'bb', component: bb },
          { path: '/cc', name: 'cc', component: cc }
        ]
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    return next()
  }
  const token = sessionStorage.getItem('token')
  console.log(token, 'token')
  if (!token) return next('/login')
  next()
})
export default router
